package com.controller;

import com.entity.User;
import com.service.IUserService;
import com.util.MD5Util;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Author: foshou.zhang
 * Date : 2016/3/9 0009
 * Time :下午 8:34
 * 管理员控制器
 */
@RequestMapping("admin")
@Controller
public class AdminController {
    @Resource
    private IUserService userService;

    /**
     * 管理员进入登陆页面
     *
     * @return
     */
    @RequestMapping("toLogin")
    public String toLogin() {
        return "adminLogin";
    }

    /**
     * 管理员登陆
     *
     * @return
     */
    @RequestMapping("adminLogin")
    public String adminLogin(User current, HttpServletRequest request) {
        User user = userService.getUserByUsername(current.getUsername());
        if (null != user && user.getPassword().equals(MD5Util.encode(current.getPassword())) && (
                user.getCategory() == 2)) {
            return "adminMain";
        } else {
            return "adminLogin";
        }
    }
}
